/*************************************************
 *FileName:      set.js
 *Description:   设置.js
 *Others:        陈灿
 *************************************************/
    /*
     * 启动
     */
    mui.init();
    mui('.mui-scroll-wrapper').scroll({
        indicators: false,      //是否显示滚动条 默认为true
        deceleration: 0.003,    //阻尼系数,系数越小滑动越灵敏 默认0.0006
        bounce: false           //是否启用回弹 默认true
    });
    /*
     * 变量初始化
     */
    
    var uid = localStorage.replace_uid;
    var token = localStorage.replace_token;
    /*
     * 主程序
     */ 
    $(document).ready(function() 
    {
        //绑定多个tap跳转页面
          bindTaps(['help','charset']);            
        //样式加载
        pagecss();
    });
    
    /**
     * pagecss
     * 样式加载
     * @cc 
     * @DateTime 2018-01-08T06:19:16+0800
     * @param    int        
     * @return   void
     */
    function pagecss(){
        if(localStorage.screens==undefined){
           localStorage.screens='true';
           $('.online').addClass('mui-active');
        }else if(localStorage.screens=='false'){
           $('.screen').removeClass('mui-active');
        }
        
        if(localStorage.mute=='true'){
           $('.mute').addClass('mui-active');
        }
        if(localStorage.shake=='true'){
           $('.shake').addClass('mui-active');
        }
        
        $('.set').on('tap','.shieldset',function(){
            $('.table-view3').fadeIn();
            $('.popover').css({display:'block'});
        })
        
        
        $('.table-view-cell-cancel').on('tap',function(){
            $('.table-view').fadeOut();
            $('.popover').css({display:'none'});
        })
        
        $('.table-view3').on('tap','.table-view-cell-a:nth-of-type(2)',function(){
            $('.table-view3').fadeOut();
            $('.table-view1').fadeIn();
        })
        
        $('.shield').on('tap',function(){
            common.pageTransition('myfriend.html?that=shield')
        })
        
        $('.phone').on('tap',function(){
            common.pageTransition('myfriend.html?that=phone')
        })
        
        $('.main').on('tap','.screen',function(){
            if($(this).hasClass('mui-active')){
                var gestures_status = '1';
            }else{
                var gestures_status = '0';
            }
            $.ajax({
                type: "post",
                url: DOMAIN_NAME + "/index.php/api/user/gesturesStatusSet",
                dataType: 'jsonp',
                data: {
                    uid: uid,
                    token: token,
                    gestures_status:gestures_status,
                },
                success: function(data) {
                    console.log(data)
                    if(data.error_code == 0) {
                        mui.toast(data.error_msg);
                        if(gestures_status == '1'){
                            localStorage.screens='true';
                        }else{
                            localStorage.screens='false';
                        }
                    } else if(data.error_code == 1001) {
                        setTimeout(function(){
                        exitlogin();
                    },1000);
                    } else {
                        mui.toast(data.error_msg);
                        if(gestures_status == '1'){
                            $('.screen').removeClass('mui-active')
                            $('.screen .mui-switch-handle').removeAttr('style');
                        }else{
                            $('.screen').addClass('mui-active')
                            $('.screen .mui-switch-handle').removeAttr('style');
                        }
                    }
                }
            });
            
        })
        
        
        
        $('.main').on('tap','.mute',function(){
            if($(this).hasClass('mui-active')){
                localStorage.mute=true;
            }else{
                localStorage.mute=false;
            }
        })
        $('.main').on('tap','.shake',function(){
            if($(this).hasClass('mui-active')){
                localStorage.shake=true;
            }else{
                localStorage.shake=false;
            }
        })
        
        $('.table-view3').on('tap','.table-view-cell:nth-of-type(1) .table-view-cell-a:nth-of-type(1)',function(){
            common.pageTransition('telephone.html')
        })
        
        $('.table-view-cell-affirm').on('tap',function(){
            var oname= $('#name').val();
            var ophone= $('#phone').val();
            var arr={};
            arr[0]={'name':oname,'mobile':ophone};
            if(ophone == '' || !/^1[3456789]\d{9}$/.test(ophone)) {
                mui.toast('请输入正确的手机号码',{duration:2000,type:'div'});
                return;
            }
            $.ajax({
                type: "post",
                url: DOMAIN_NAME + "/index.php/api/user/shieldListAdd",
                dataType: 'jsonp',
                data: {
                    uid: uid,
                    token: token,
                    list:arr,
                },
                success: function(data) {
                    if(data.error_code == 0) {
                        mui.toast('屏蔽成功!');
                        $('#name').val('');
                        $('#phone').val('');
                        $('.table-view').fadeOut();
                        $('.popover').css({display:'none'});
                    } else if(data.error_code == 1001) {
                        setTimeout(function(){
                        exitlogin();
                    },1000);
                    } else {
                        mui.toast('屏蔽失败！');
                    }
                }
            });
        })
    }
    /**
     * adds //方法名
     * @陈灿 //作者名
     * @DateTime 2018-01-010T0116:25:00+0800 //时间
     * @param    int    $goods_id //参数
     * @param    array  $data //参数
     * @return    array  [error_code, error_msg, goods_id] //返回值
     */